﻿<%@ Page Language="C#" validateRequest="false" AutoEventWireup="true" CodeBehind="ArticleEdit.aspx.cs" Inherits="hcms.Admin.ArticleEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>编辑文档</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<link href="Styles/rightframe.css" rel="stylesheet" type="text/css" />
	<script src="/Scripts/jquery.min.161.js" type="text/javascript"></script>
	<script src="/Scripts/comm.js" type="text/javascript"></script>
	<script src="js/admin.js" type="text/javascript"></script>
<script charset="utf-8" src="/plugins/kindeditor-4.1.1/kindeditor-min.js" type="text/javascript"></script>
<script charset="utf-8" src="/plugins/kindeditor-4.1.1/lang/zh_CN.js" type="text/javascript"></script>
<style type="text/css">
	.sty1 td{ vertical-align:top; }
	.sty1 td.gray, .sty1 td.black{ padding-top:3px; text-align:right; }
	#editor_id { width:798px; height:400px; }
	#htmAssociate { width:505px; height:138px; }
</style>
<script type="text/javascript">
	var submitting = false;
	var editor;

	function onsave() {
		try {
			$(".submitstate").html("");
			var ids = window.parent.getSelects();
			if (ids.length === 0)
				throw (new Error("至少勾选一个栏目。"));

			$("#htmcids").val(ids.join(','));

			//$("#idsubmit")[0].disabled = true; //?? 防止重复提交，不能防止页面刷新
			if (submitting) //?? 防止重复提交，不能防止页面刷新
				return;

			submitting = true;

			$("#idtitle").verifyEmpty();
			editor.sync(); // 同步编辑框数据
			$("#editor_id").verifyLength(2, 50000);	// 最多五万字
			//$("#idupdatetime").verifyEmpty();
			$("#cmd").val("save");
			//$("#code").val($("#code").val().replace(new RegExp("<", "gm"), "&1l1t1;"));
			$(".submitstate").html("......");
			form1.submit();
		}
		catch (err) {
			alert(err.message);
			submitting = false;
			//$("#idsubmit")[0].disabled = false;
		}
	}

	function onbrowser() {
		if ($("#htmaid").val() == "") {
			alert("保存文件后才能浏览。");
			return;
		}
		window.open("/Articles/<%=cid%>-" + $("#htmaid").val() + ".htm");
	}

	function oncomment() {
		if ($("#htmaid").val() == "") {
			alert("新建文档没有评论。");
			return;
		}
		window.location = 'CommentList.aspx?aid=' + $("#htmaid").val() + '&cid=<%=cid%>';
	}

	// 初始化
	$(function () {
	    // 初始化编辑框
	    KindEditor.ready(function (K) {
	        var options = {
	            uploadJson: '/plugins/kindeditor-4.1.1/asp.net/upload_json.ashx',
	            fileManagerJson: '/plugins/kindeditor-4.1.1/asp.net/file_manager_json.ashx',

	            //resizeType: 1,
	            filterMode: false, // 不过滤任何标签，否则iframe等被删除了
	            allowPreviewEmoticons: false,
	            allowImageUpload: true
	            //items: [
	            //		'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
	            //		'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
	            //		'insertunorderedlist', '|', 'emoticons', 'image', 'link', '|', ]
	        };

	        // ## 如果代码开头是<code/>,则只能进入代码编辑状态,必须小写。
	        if ($("#editor_id").val().substring(0, 7) == "<code/>") {
	            options["items"] = [];
	            options["designMode"] = false;
	        }
	        editor = K.create('#editor_id', options);
	    });

	    // 初始化栏目树
	    window.parent.setSelects($("#htmcids").val());
	    window.parent.setActive("<%=cid%>");

	    // 自知应大小
	    //$(window).resize(function () {
	    //	$("#editor_id").height($(window).height() - 215);
	    //	$("#editor_id").width($(window).width() - 30);
	    //});
	});
</script>
</head>
<body>
    <form id="form1" runat="server">
	<input type="hidden" id="cmd" runat="server" />
	<input type="hidden" id="htmaid" runat="server" />
	<input type="hidden" id="htmcids" runat="server" />
	<div class="topdiv">
		<a href="ColumnList.aspx">栏目管理</a>
		<% foreach (System.Data.DataRow row in posrows)
	 { %>&gt;&gt; <a href="ColumnList.aspx?cid=<%=row["colID"]%>"><%=row["colName"]%></a>
		<%
	 } %>&gt;&gt; <%=editname%>&nbsp;&nbsp;&nbsp;
		<input type="button" onclick="onsave()" value="保存" />&nbsp;<span class="submitstate"><%=submitstate %></span>&nbsp;&nbsp;
		<input type="button" onclick="onbrowser()" value="浏览" />&nbsp;&nbsp;
		<input type="button" onclick="oncomment()" value="评论管理" />&nbsp;
		<%--所属栏目：<span id="htmcnames" runat="server"></span>--%>
	</div>
	<br />
	<table class="sty1" cellpadding="0" cellspacing="5" border="0">
		<tr>
			<td class="black" width="80px">文档标题：</td>
			<td width="800px"><input id="idtitle" class="w800" type="text" runat="server" /></td>
		</tr>
		<tr>
			<td class="black">文档内容：</td>
			<td><textarea runat="server" id="editor_id"></textarea></td>
		</tr>
		<tr>
			<td class="black" width="80px">网页标题：</td>
			<td width="800px"><input id="htmBrowserTitle" class="w800" type="text" runat="server" /></td>
		</tr>
	</table>
	<table class="sty1" cellpadding="0" cellspacing="5" border="0">
		<tr>
			<td class="black" width="80px">发布时间：</td>
			<td><input id="idupdatetime" type="text" class="w200" runat="server" 
					disabled="disabled" /></td>
			<td class="gray" width="80px" rowspan="5">相关连接：<br /><br />加入相关<br />文档的地<br />址，只取<br />文件名部<br />分，用回<br />车分隔。</td>
			<td rowspan="5"><textarea runat="server" id="htmAssociate"></textarea></td>
		</tr>
		<tr>
			<td class="black">发布人：</td>
			<td><input id="iduser" type="text" class="w200" runat="server" 
					disabled="disabled" /></td>
		</tr>
		<tr>
			<td class="gray">文档模板：</td>
			<td><asp:DropDownList ID="idarttemplate" 
		runat="server" Width="206px">
	</asp:DropDownList></td>
		</tr>
		<tr>
			<td class="gray">来源：</td>
			<td><input id="idsource" class="w200" type="text" runat="server" /></td>
		</tr>
		<tr>
			<td class="gray">级别：</td>
			<td><input id="idlevel" class="w200" type="text" runat="server" /></td>
		</tr>
		<tr>
			<td class="gray"></td>
			<td><br /><input type="button" onclick="onsave()" value="保存" />&nbsp;<span class="submitstate"><%=submitstate %></span>
		&nbsp;
		<input type="button" onclick="onbrowser()" value="浏览" /></td>
		</tr>
	</table>
    </form>
</body>
</html>
